package com.item.service.impl;

import com.github.pagehelper.PageHelper;
import com.item.domain.TbUserLike;
import com.item.mapper.TbUserLikeMapper;
import com.item.po.TbUserLikePo;
import com.item.service.TbUserLikeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class TbUserLikeServiceImpl implements TbUserLikeService {

    @Autowired
    TbUserLikeMapper tbUserLikeMapper;


    public List<TbUserLike> findAll(int limit, int page, TbUserLikePo tbUserLike) {
        if (limit > 0 && page > 0) {
            PageHelper.startPage(limit, page);
        }
        return tbUserLikeMapper.findAll(tbUserLike);
    }


    public int add(TbUserLike tbUserLike) {

        TbUserLike userLike = tbUserLikeMapper.selectFindAll(tbUserLike);
        try {
            if (userLike != null) {
                tbUserLikeMapper.deleteTyId(tbUserLike);
            } else {
                tbUserLikeMapper.insertSelective(tbUserLike);
            }
            return 1;
        } catch (Exception e) {
            return 0;
        }

    }


    public int update(TbUserLike tbUserLike) {
        return tbUserLikeMapper.updateByPrimaryKey(tbUserLike);
    }

    @Override
    public int delete(int id) {
        return tbUserLikeMapper.deleteByPrimaryKey(id);
    }
}
